package com.warningrc.module.user.struts.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.warningrc.module.user.service.UserService;
import com.warningrc.module.user.vo.UserVo;

public class UserAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserVo user;
	private List<UserVo> allUser;
	private UserService userService;

	public List<UserVo> getAllUser() {
		return allUser;
	}

	public void setAllUser(List<UserVo> allUser) {
		this.allUser = allUser;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserVo getUser() {
		return user;
	}

	public void setUser(UserVo user) {
		this.user = user;
	}

	public String index() {
		allUser = userService.getAll();
		return "index";
	}

	public String view() {
		user = userService.getUser(user.getUserId());
		if (user == null)
			return "null";
		return "view";
	}

	public String create() {
		user.setUserId((String) userService.saveUser(user));
		return "create";
	}

	public String update() {
		userService.updateUser(user);
		return "update";
	}

	public String delete() {
		userService.deleteUser(user.getUserId());
		return "delete";
	}
}
